#include "../../source/common/log.hpp"
#include "../../source/client/rpc_client.hpp"

#include <memory>
#include <functional>
#include <thread>

void callBack(const Json::Value &result)
{
    LOG(JsonMuduoRPC::DEBUG, "result: %d", result.asInt());
}

int main()
{
    JsonMuduoRPC::client::RPCClient::ptr client = std::make_shared<JsonMuduoRPC::client::RPCClient>(false, "127.0.0.1", 8080);

    Json::Value params;
    params["num1"] = 11;
    params["num2"] = 22;
    Json::Value result;
    bool ret = client->call("ADD", params, result);
    if (ret == false)
        LOG(JsonMuduoRPC::ERROR, "请求处理失败");
    else
        LOG(JsonMuduoRPC::DEBUG, "result: %d", result.asInt());

    params["num1"] = 33;
    params["num2"] = 44;
    JsonMuduoRPC::client::RPCCaller::JsonAsyncResponse async_result;
    ret = client->call("ADD", params, async_result);
    if (ret == false)
        LOG(JsonMuduoRPC::ERROR, "请求处理失败");
    else
        LOG(JsonMuduoRPC::DEBUG, "result: %d", async_result.get().asInt());

    params["num1"] = 55;
    params["num2"] = 66;
    ret = client->call("ADD", params, callBack);
    if (ret == false)
        LOG(JsonMuduoRPC::ERROR, "请求处理失败");

    std::this_thread::sleep_for(std::chrono::seconds(10));
    return 0;
}